$(function () {

//点击切换右侧显示
    var showlist=['内存分布显示', '存储分布显示', 'CPU分布显示'];
    $('.lefteach').on('click','.memory',function () {
        $('.ziyuanpaiming').text(showlist[$(this).index()]);
    });
//右侧数据切换
    $('.linkto').on('click','div',function () {
        $(this).addClass('active').siblings().removeClass('active');
        $(".linkdata>div:eq("+$(this).index()+")").css('display','block').siblings().css('display','none');
    })

//获取数据
    function geturldata(option) {
        var result='';
        $.ajax({
            type : "get",
            url : option.url,
            dataType:"json",
            async:false,
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            success : function(data) {
               result=data;
            }
        });
        return result;
    }

    $('.data_cpu').text(geturldata({url:"/api/cpus"}));
    $('.data_memory').text(geturldata({url:"/api/memorys"}));
    $('.data_storages').text(geturldata({url:"/api/storages"}));

//cpu数据显示
    var getservices_cpu = geturldata({url:"/api/services-cpu"})

    var setlistdata =new SetListData(getservices_cpu,getservices_cpu[0].cpu);
    $(".link_cpu_data").append(setlistdata);

//页面跳转
    $('.linkdata').on('click','div',function () {
        location.href='hrsocial.html';
    })

// 总内存中的竖条
    var tiaozhuang = function () {
        var htmltext='';
        for(var i=0;i<26;i++){
                htmltext += '<span class="tiaozhuang"></span>';
        }
        $('.shutiao').html(htmltext);
        $('.shutiao1').find('span:lt(14)').css('borderColor','#1fc4ba');
        $('.shutiao2').find('span:lt(21)').css('borderColor','#1fc4ba');
        $('.shutiao3').find('span:lt(18)').css('borderColor','#1fc4ba');
    };
    tiaozhuang();


// 底部折线图
    var jifangshidu = echarts.init(document.getElementById('jifangshidu')),
        jifangwendu = echarts.init(document.getElementById('jifangwendu')),
        jifangdianliu = echarts.init(document.getElementById('jifangdianliu')),
        gongjiweixie = echarts.init(document.getElementById('gongjiweixie')),
        xitongfangwenqushi = echarts.init(document.getElementById('xitongfangwenqushi'));
    var shidudata={data:[2,30,25,35,20,15,35,50,30,8],listname:'机房湿度',perce:'50%',color:"#6d9bfb",bgcolor:'#6d9bfb'},
        wendudata={data:[22,20,25,35,20,25,15,20,15,10],listname:'机房湿度',perce:'22℃',color:"#57ffff",bgcolor:'#1a6b97'},
        dianliudata={data:[5,10,15,10,15,15,13,2,15,18],listname:'机房湿度',perce:'20A',color:"#a37bdc",bgcolor:'#31438c'},
        gongjidata={data:[22,20,15,25,20,15,18,10,8,7],listname:'机房湿度',perce:'61.7%',color:"#47d98d",bgcolor:'#156075'},
        xitongfangwen={data:[2,7,2,5,10,5,6,10,5,2],listname:'机房湿度',perce:'1000',color:"#2e4c78",bgcolor:'#999999'};

    var getshidudata = new GetOption(shidudata),
        getwendudata = new GetOption(wendudata),
        getdianliudata = new GetOption(dianliudata),
        getgongjidata = new GetOption(gongjidata),
        getxitongfangwen = new GetOption(xitongfangwen)
    jifangshidu.setOption(getshidudata);
    jifangwendu.setOption(getwendudata);
    jifangdianliu.setOption(getdianliudata);
    gongjiweixie.setOption(getgongjidata);
    xitongfangwenqushi.setOption(getxitongfangwen);
    window.addEventListener("resize",function(){
        jifangshidu.resize()
        jifangwendu.resize();
        jifangdianliu.resize();
        gongjiweixie.resize();
        xitongfangwenqushi.resize();

    });

})